#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct person {
    char name[10];
    int  age;
} Person;

typedef struct teacher {
    Person p;
    int    teach_age;
} Teacher;

typedef struct student {
    Person p;
    int    learning_age;
} Student;

Teacher *create_teacher(const char *name, int teach_age)
{
    Teacher *t = NULL;

    t = (Teacher *)malloc(sizeof(Teacher));

    memset(t, 0, sizeof(Teacher));
    strcpy(t->p.name, name);
    t->p.age     = 0;
    t->teach_age = 20;
    return t;
}

Teacher *destroy_teacher(Teacher *t)
{
    if (t != NULL) {
        free(t);
    }
    return NULL;
}

Student *create_student(const char *name, int learning_age)
{
    Student *s = NULL;

    s = (Student *)malloc(sizeof(Student));

    memset(s, 0, sizeof(Teacher));
    strcpy(s->p.name, name);
    s->p.age        = 0;
    s->learning_age = 20;
    return s;
}

Student *destroy_student(Student *s)
{
    if (s != NULL) {
        free(s);
    }
    return NULL;
}

void print_student(Student *s)
{
    printf("student: %p {\"name\":\"%s\", \"age\":%d, \"learning_age\":%d}\n",
           s, s->p.name, s->p.age, s->learning_age);
}

void print_teacher(Teacher *t)
{
    printf("teacher: %p {\"name\":\"%s\", \"age\":%d, \"teach_age\":%d}\n", t,
           t->p.name, t->p.age, t->teach_age);
}

int main()
{
    char *   name         = "John";
    int      teach_age    = 2;
    int      learning_age = 10;
    Student *s            = NULL;
    Teacher *t            = NULL;

    s = create_student(name, learning_age);
    print_student(s);

    t = create_teacher(name, teach_age);
    print_teacher(t);

    s = destroy_student(s);

    t = destroy_teacher(t);

    return 0;
}
